package com.imooc.trading_system.controller;


import com.imooc.trading_system.service.ProductService;
import com.imooc.trading_system.utils.JsonData;
import com.imooc.trading_system.vo.product.GetProductDetailReqVO;
import com.imooc.trading_system.vo.product.PublishProductReqVO;
import com.imooc.trading_system.vo.product.SearchProductListReqVO;
import com.imooc.trading_system.vo.tradingHall.TradingHallSearchProductListReqVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author Feng zhaoxi
 * @since 2022-04-24
 */
@RestController
@RequestMapping("/api/product")
public class ProductController {
    @Autowired
    private ProductService productService;


    /**
     * 上传产品图片
     *
     * @param file
     * @return
     * @throws Exception
     */
    @RequestMapping("upload_img")
    public JsonData uploadProductImg(@RequestParam("file") MultipartFile file) {
        return productService.uploadProductImg(file);
    }

    /**
     * 上传产品详情图片
     *
     * @param file
     * @param product_id
     * @return
     */
//    @RequestMapping("upload_detail_img")
//    public JsonData uploadProductDetailImg(@RequestParam("file") MultipartFile file, @RequestParam("product_id") int product_id) {
//        //todo 产品详情图片
//        return productService.uploadProductDetailImg(file, product_id);
//    }

    /**
     * 发布产品
     *
     * @param publishProductReqVO
     * @return
     */
    @PostMapping("publish_product")
    public JsonData publishProduct(@RequestBody @Valid PublishProductReqVO publishProductReqVO) {
        return productService.publishProduct(publishProductReqVO);
    }

    /**
     * 获取产品列表
     *
     * @param searchProductListReqVO
     * @return
     */
    @PostMapping("product_list")
    public JsonData getProductList(@RequestBody SearchProductListReqVO searchProductListReqVO) {
        return productService.getProductList(searchProductListReqVO);
    }

    /**
     * 根据id获取产品详情
     *
     * @param getProductDetailReqVO
     * @return
     */
    @PostMapping("get_product_detail")
    public JsonData getProductDetail(@RequestBody GetProductDetailReqVO getProductDetailReqVO) {
        return productService.getProductDetail(getProductDetailReqVO);
    }

    /**
     * 产品下架
     *
     * @param getProductDetailReqVO
     * @return
     */
    @PostMapping("down_shelves")
    public JsonData downShelves(@RequestBody GetProductDetailReqVO getProductDetailReqVO) {
        return productService.downShelves(getProductDetailReqVO);
    }


    /**
     * 市场查询产品
     *
     * @param tradingHallSearchProductListReqVO
     * @return
     */
    @PostMapping("search_product")
    public JsonData searchProductList(@RequestBody TradingHallSearchProductListReqVO tradingHallSearchProductListReqVO) {
        return productService.searchProductList(tradingHallSearchProductListReqVO);
    }

}

